		//通栏广告位1
		var index=0; 
		function changeAd1(i,cls){ 
			var a=$("."+cls).eq(i).find("a"); 
			if(index>($("."+cls).eq(i).find("a").length-1)||index==$("."+cls).eq(i).find("a").length-1){ 
				index=0; 
			}else{ 
				index++;  
			} 
			a.css("display","none");
			a.eq(index).css("display",""); 
		} 
		var inter1 = parseInt($(".advier").eq(0).attr("interval"))*1000;
		setInterval(function(){
				//$(".advier").eq(0).find("a");
				changeAd1(0,"advier");
				/* for(var i = 0; i<$(".advier").length;i++){ */
					var title = $(".advier").eq(0).find("a:not([style])").attr("title");
					//alert(title);
				/* } */
				//inter = parseInt($(".advier").eq(0).attr("adInterval"))*1000;
				//alert($('.advier a:not([style])').attr("title"));
			},
			inter1
		); 
		//通栏广告位2
		var index1=0;
		function changeAd2(i,cls){ 
			var a=$("."+cls).eq(i).find("a"); 
			if(index1>($("."+cls).eq(i).find("a").length-1)||index1==$("."+cls).eq(i).find("a").length-1){ 
				index1=0; 
			}else{ 
				index1++;  
			} 
			a.css("display","none");
			a.eq(index1).css("display",""); 
		}
		var inter2 = parseInt($(".advier").eq(1).attr("interval"))*1000;
		setInterval(function(){
			changeAd2(1,"advier");
				var title = $(".advier").eq(1).find("a:not([style])").attr("title");
				//alert(title);
			},
			inter2
		); 
		//通栏广告位3
		var index3=0; 
		function changeAd3(i,cls){ 
			var a=$("."+cls).eq(i).find("a"); 
			if(index3>($("."+cls).eq(i).find("a").length-1)||index3==$("."+cls).eq(i).find("a").length-1){ 
				index3=0;
			}else{ 
				index3++;
			} 
			a.css("display","none");
			a.eq(index3).css("display",""); 
		} 
		var inter3 = parseInt($(".advier").eq(2).attr("interval"))*1000;
		setInterval(function(){
				changeAd3(2,"advier");
				var title = $(".advier").eq(2).find("a:not([style])").attr("title");
				//alert(title);
			},
			inter3
		);
		//矩形广告位1
		var ind1=0; 
		function change1(i,cls){ 
			var a=$("."+cls).eq(i).find("a"); 
			if(ind1>($("."+cls).eq(i).find("a").length-1)||ind1==$("."+cls).eq(i).find("a").length-1){ 
				ind1=0;
			}else{ 
				ind1++;
			} 
			a.css("display","none");
			a.eq(ind1).css("display",""); 
		} 
		var inte1 = parseInt($(".ggao").eq(0).attr("interval"))*1000;
		setInterval(function(){
				change1(0,"ggao");
				var title = $(".ggao").eq(0).find("a:not([style])").attr("title");
				//alert(title);
			},
			inte1
		);
		//矩形广告位2
		var ind2=0; 
		function change2(i,cls){ 
			var a=$("."+cls).eq(i).find("a"); 
			if(ind2>($("."+cls).eq(i).find("a").length-1)||ind2==$("."+cls).eq(i).find("a").length-1){ 
				ind2=0;
			}else{ 
				ind2++;
			} 
			a.css("display","none");
			a.eq(ind2).css("display",""); 
			//changeAdInsert(a.eq(ind2));
		} 
		var inte2 = parseInt($(".ggao").eq(1).attr("interval"))*1000;
		setInterval(function(){
				change2(1,"ggao");
				var title = $(".ggao").eq(1).find("a:not([style])").attr("title");
				//alert(title);
			},
			inte2
		);
		//矩形广告位3
		var ind3=0; 
		function change3(i,cls){ 
			var a=$("."+cls).eq(i).find("a"); 
			if(ind3>($("."+cls).eq(i).find("a").length-1)||ind3==$("."+cls).eq(i).find("a").length-1){ 
				ind3=0;
			}else{ 
				ind3++;
			} 
			a.css("display","none");
			a.eq(ind3).css("display",""); 
		} 
		var inte3 = parseInt($(".ggao").eq(2).attr("interval"))*1000;
		setInterval(function(){
				change3(2,"ggao");
				var title = $(".ggao").eq(2).find("a:not([style])").attr("title");
				//alert(title);
			},
			inte3
		);
		//获取某广告位的所有广告
		function getAdByPosition(data){
			var code = data;
			$.ajax({
				type: "POST",
			     url: basePath+"/ad/getad",
			    data: {positionCode:data} ,
			    dataType: "json",
			    success: function(data){
			    	if(data!=null && data!=''){
			    		var html = buildAd(data);
				    	$("#"+code).eq(0).append(html);
				    	var size = $("#"+code).attr("size").split('*');
				    	var w = size[0];
				    	var h = size[1];
				    	$("#"+code+" img").attr("style","height:"+h+"px;width:"+w+"px");
				    	
			    	}
			    },
			    error:function(){
			    	alert("广告异常！");
			    }
			});
			
		}
		
		//生成对应广告位的条目
		function buildAd(data){
			var json = eval(data);
			var html = "";
			$.each(
					json,
					function(i,item)
					{
						if(i==0){
							html+="<a hrefs="+item.linkUrl+ " onclick='clickAdInsert(this)' target='_blank' id="
							+item.id+" title="+item.title+" type="+item.type+" typeName="+item.typeName+">";
							html+="<img src="+baseImgPath+item.resourceUrl+" alt='' >";
							html+="</img></a>";
						}else{
							html+="<a hrefs=" +item.linkUrl+" style='display:none' onclick='clickAdInsert(this)' target='_blank' id="
							+item.id+" title="+item.title+" type="+item.type+" typeName="+item.typeName+">";
							html+="<img src="+baseImgPath+item.resourceUrl+" alt='' >";
							html+="</img></a>";
						}
					
					}
			);
			return html;
			
		}
		//点击插入广告
		function clickAdInsert(obj){
			$.get("http://ipinfo.io/json",function(data){
				var ipCode="";
				var json=eval(data);
				var ipCode = json.ip;
				var $this=$(obj);
				//点击的是a标签
	        	var params={};
	        	params["adpositionCode"]=$this.parent().attr("id");
	        	params["adpositionName"]=$this.parent().attr("name");
	        	params["adResourceId"]=$this.attr("id");
	        	params["adResourceTitle"]=$this.attr("title");
	        	params["adTypeName"]=$this.attr("typeName");
	        	params["adTypeCode"]=$this.attr("type");
	        	params["ip"]=ipCode;
	        	params["type"]="d";
	        	params["count"]="1";
	        	$.ajax({
	    			type:"POST",
	    			data:params,
	    			url:basePath+"/common/addAdRecord.html",
	    			success:function(){
	    				window.location.href=$this.attr("hrefs");
	    			},
	    			error:function(){
	    				alert("error");
	    			}
	    		}); 
	        	
			});
		}
		
		//切换浏览广告
		function changeAdInsert(obj){
			$.get("http://ipinfo.io/json",function(data){
				var ipCode="";
				var json=eval(data);
				var ipCode = json.ip;
				var $this=$(obj);
				//点击的是a标签
	        	var params={};
	        	params["adpositionCode"]=$this.parent().attr("id");
	        	params["adpositionName"]=$this.parent().attr("name");
	        	params["adResourceId"]=$this.attr("id");
	        	params["adResourceTitle"]=$this.attr("title");
	        	params["adTypeName"]=$this.attr("typeName");
	        	params["adTypeCode"]=$this.attr("type");
	        	params["ip"]=ipCode;
	        	params["type"]="d";
	        	params["count"]="1";
	        	$.ajax({
	    			type:"POST",
	    			data:params,
	    			url:basePath+"/common/addAdRecord.html",
	    			success:function(){
	    				//alert("success");
	    			},
	    			error:function(){
	    				alert("error");
	    			}
	    		}); 
	        	
			});
		}
		